package com.toumy.controller;

import com.toumy.domain.Code;
import com.toumy.domain.Result;
import com.toumy.domain.User;
import com.toumy.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private IUserService userService;

    @GetMapping("/{id}")
    public Result getById(@PathVariable int id){
        User user = userService.selectById(id);

        return user != null?new Result(Code.FIND_S,user,"查找成功"):new Result(Code.FIND_F,null,"查找失败");
    }

    @GetMapping
    public Result getByUsername(@RequestBody User user){
        String username = user.getUsername();
        User user1 = userService.selectByUsername(username);

        return user1.getPassword() == user.getPassword()?new Result(Code.FIND_S,user1,"登陆成功"):new Result(Code.FIND_F,null,"登录失败");
    }
}
